package udf.matching;

import java.io.*;

import org.apache.pig.FilterFunc;

import org.apache.pig.data.Tuple;

import udf.string.CleanTag;

public class IsInvalidTAG extends FilterFunc {

	static  private CleanTag cleaner = null;
	boolean initialized= false;
	public void init(Tuple tuple) throws IOException {
		/*
		 * for (int count = 1; count < tuple.size(); count++) { if
		 * (!(tuple.get(count) instanceof String)) { String msg =
		 * "LookupInFiles : Filename should be a string."; throw new
		 * IOException(msg); } mFiles.add((String) tuple.get(count)); }
		 */

		String domain_path = (String) tuple.get(1);
		
		
		cleaner = new CleanTag(domain_path);
		
		initialized = true;
	}

	
	
	@Override
	public Boolean exec(Tuple input) throws IOException {

		if (input.size() != 2 || input.get(0) == null) {
			return null;

		}

		else {

			String tag = (String) input.get(0);
			String path = (String) input.get(1);

			if (cleaner == null) {

				cleaner = new CleanTag(path);

			}

			return cleaner.isTagTrash(tag);

		}

	}
}
